package axdoc.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.mongodb.core.MongoTemplate;

import axdoc.model.SelectValue;
import axdoc.model.mongo.City;
import axdoc.model.mongo.Pdept;
import axdoc.model.mongo.Title;
import axdoc.service.InfoService;

public class InfoServiceImpl implements InfoService {

	MongoTemplate mongoTemplate;

	public MongoTemplate getMongoTemplate() {
		return mongoTemplate;
	}

	public void setMongoTemplate(MongoTemplate mongoTemplate) {
		this.mongoTemplate = mongoTemplate;
	}

	@Override
	public List<SelectValue> getTiltles() {
		List<Title> list = mongoTemplate.findAll(Title.class);
		List<SelectValue> rules = new ArrayList<SelectValue>();
		SelectValue sv0 = new SelectValue();
		sv0.setId("0");
		sv0.setName("全部");
		rules.add(sv0);
		if (list != null && list.size() > 0) {
			for (Title t : list) {
				SelectValue sv = new SelectValue();
				sv.setId(t.get_id());
				sv.setName(t.getName());
				rules.add(sv);
			}
		}
		return rules;
	};

	@Override
	public List<SelectValue> getCities() {
		List<City> list = mongoTemplate.findAll(City.class);
		List<SelectValue> rules = new ArrayList<SelectValue>();
		SelectValue sv0 = new SelectValue();
		sv0.setId("0");
		sv0.setName("全部");
		rules.add(sv0);
		if (list != null && list.size() > 0) {
			for (City t : list) {
				SelectValue sv = new SelectValue();
				sv.setId(t.get_id());
				sv.setName(t.getName());
				rules.add(sv);
			}
		}
		return rules;
	}

	@Override
	public List<SelectValue> getPdepts() {
		List<Pdept> list = mongoTemplate.findAll(Pdept.class);
		List<SelectValue> rules = new ArrayList<SelectValue>();
		SelectValue sv0 = new SelectValue();
		sv0.setId("0");
		sv0.setName("全部");
		rules.add(sv0);
		if (list != null && list.size() > 0) {
			for (Pdept t : list) {
				SelectValue sv = new SelectValue();
				sv.setId(t.get_id());
				sv.setName(t.getName());
				rules.add(sv);
			}
		}
		return rules;
	}
}
